<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) in pages" :key="index">
        <div class="icon"
             v-for="item in page"
             :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl" />
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
      // iconList: [{
      //   id: '0001',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
      //   imgDesc: '热门景点'
      // }, {
      //   id: '0002',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/67/9a1678221b8e0e02.png',
      //   imgDesc: '古镇风光'
      // }, {
      //   id: '0003',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/ab/6f7d6e44963c9302.png',
      //   imgDesc: '泡温泉'
      // }, {
      //   id: '0004',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/17/99402a22ce4af302.png',
      //   imgDesc: '园林景致'
      // }, {
      //   id: '0005',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/47/c2b659e048b11602.png',
      //   imgDesc: '动物乐园'
      // }, {
      //   id: '0006',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/75/eca3ce656c886502.png',
      //   imgDesc: '湖畔风光'
      // }, {
      //   id: '0007',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/fc/b10a6b2e4f0fe102.png',
      //   imgDesc: '户外滑雪'
      // }, {
      //   id: '0008',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/f5/a963333e1fa802.png',
      //   imgDesc: '吃喝玩乐'
      // }, {
      //   id: '0009',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
      //   imgDesc: '一日游'
      // }, {
      //   id: '0010',
      //   imgUrl: 'http://img1.qunarzz.com/piao/fusion/1803/c1/6f15f887179fa002.png',
      //   imgDesc: '寺院风光'
      // }]
    }
  },
  computed: {
    pages () {
      // 将iconsList中的内容分页划分成为多个List，
      // v-for对象：iconList -> page
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  @import "~styles/mixins.styl"
   .icons >>> .swiper-container{
     /*overflow: hidden*/
     /*width: 100%*/
     height: 0
     padding-bottom: 50%
   }
  .icons{
    margin-top .1rem
    .icon{
      position: relative
      overflow: hidden
      float: left
      width: 25%
      height: 0
      padding-bottom: 25%
      /*background: yellow*/
      .icon-img{
        position : absolute
        top: 0
        left : 0
        right : 0
        bottom: .44rem
        box-sizing: border-box
        padding: .1rem
        /*background red*/
        .icon-img-content{
          display: block
          margin: 0 auto
          height: 100%
        }
      }
      .icon-desc{
        position absolute
        bottom 0
        left 0
        right 0
        text-align center
        height .44rem
        line-height .44rem
        color $darkTextColor
        //解决文本溢出
        ellipsis()
      }
    }
  }
</style>
